/* 子功能 */
<template>
  <div class="childfun-config">
    <je-form-item label="快速定位" name="quickPositioning">
      <!-- <je-checkbox v-model:checked="formState.quickPositioning" /> -->
      <je-switch v-model:value="formState.quickPositioning" mode="checkbox" />
      <span class="prompt">启动后可完成快速定位。</span>
    </je-form-item>
  </div>
</template>
<script>
  import { defineComponent, reactive, watch, ref } from 'vue';
  import { Form, Switch } from '@jecloud/ui';
  import { decode } from '@jecloud/utils';
  import { useInjectOtherCOnfig } from '../context';

  export default defineComponent({
    name: 'ChildfunConfig',
    components: {
      JeFormItem: Form.Item,
      JeSwitch: Switch,
    },
    props: {
      otherConfig: {
        type: String,
        default: '',
      },
    },
    setup(props, { expose }) {
      const parentContext = useInjectOtherCOnfig();
      const config = (props.otherConfig && decode(props.otherConfig ?? '{}')) ?? {};
      const formState = reactive({
        quickPositioning: config.quickPositioning || false, //快速定位
      });

      watch(
        () => formState,
        () => {
          parentContext.setConfig(formState);
        },
        { deep: true },
      );

      //暴露表单值用于父组件赋值
      expose({
        formState,
      });

      return { formState };
    },
  });
</script>
<style lang="less" scoped></style>
